package cn.edu.scau.cmi.yangzhengkai.client.classicsDesignPattern;

import cn.edu.scau.cmi.yangzhengkai.multipleton.Marshal;
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class MultipletonClient extends Application {

	/*
	 * (non-Javadoc)
	 * 
	 * @see javafx.application.Application#start(javafx.stage.Stage)
	 */
	@Override
	public void start(Stage primaryStage) {

		FlowPane fp = new FlowPane();
		HBox hb = new HBox();
		TextField tfMessage = new TextField();
		fp.getChildren().add(hb);
		Button bu = new Button("创建元帅");
		hb.getChildren().addAll(tfMessage, bu);
		fp.setOrientation(Orientation.VERTICAL);
		bu.setOnAction(MouseEvent -> {
			Label lb = new Label();
			Marshal marshal = Marshal.getMarshal(tfMessage.getText());
			if (marshal == null) {
				lb = new Label("已创建十大元帅，无法继续创建");
			} else {
				String str = marshal.getName() + marshal.toString();
				lb = new Label(str);
			}
			fp.getChildren().add(lb);
		});

		Scene scene = new Scene(fp);
		primaryStage.setScene(scene);
		primaryStage.setHeight(500);
		primaryStage.setWidth(500);
		primaryStage.show();

	}

	public static void main(String args[]) {
		Application.launch(args);
	}

}
